unit uRewardRecord;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,BaseForm,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, cxGraphics, cxControls, cxLookAndFeels,
  cxLookAndFeelPainters, dxSkinsCore, dxSkinBlack, dxSkinBlue, dxSkinBlueprint,
  dxSkinCaramel, dxSkinCoffee, dxSkinDarkRoom, dxSkinDarkSide,
  dxSkinDevExpressDarkStyle, dxSkinDevExpressStyle, dxSkinFoggy,
  dxSkinGlassOceans, dxSkinHighContrast, dxSkiniMaginary, dxSkinLilian,
  dxSkinLiquidSky, dxSkinLondonLiquidSky, dxSkinMcSkin, dxSkinMoneyTwins,
  dxSkinOffice2007Black, dxSkinOffice2007Blue, dxSkinOffice2007Green,
  dxSkinOffice2007Pink, dxSkinOffice2007Silver, dxSkinOffice2010Black,
  dxSkinOffice2010Blue, dxSkinOffice2010Silver, dxSkinPumpkin, dxSkinSeven,
  dxSkinSevenClassic, dxSkinSharp, dxSkinSharpPlus, dxSkinSilver,
  dxSkinSpringTime, dxSkinStardust, dxSkinSummer2008, dxSkinTheAsphaltWorld,
  dxSkinsDefaultPainters, dxSkinValentine, dxSkinVS2010, dxSkinWhiteprint,
  dxSkinXmas2008Blue, dxSkinscxPCPainter, cxPCdxBarPopupMenu, cxStyles,
  cxCustomData, cxFilter, cxData, cxDataStorage, cxEdit, cxNavigator, Data.DB,
  cxDBData, cxImageComboBox, cxMemo, cxContainer, Vcl.ComCtrls, dxCore,
  cxDateUtils, Vcl.Menus, Vcl.ActnList, Datasnap.DBClient, ClientRowSet,
  Vcl.StdCtrls, cxButtons, cxDropDownEdit, cxTextEdit, cxMaskEdit, cxCalendar,
  cxGroupBox, cxGridLevel, cxGridCustomTableView, cxGridTableView,
  cxGridDBTableView, cxClasses, cxGridCustomView, cxGrid, cxPC;

type
  TFrmRewardRecord = class(TBaseForm)
    cxPageControl1: TcxPageControl;
    cxTabSheet1: TcxTabSheet;
    GrdBasic: TcxGrid;
    tvBasic: TcxGridDBTableView;
    tvBasicBILL_NO: TcxGridDBColumn;
    tvBasicPAY_TIME: TcxGridDBColumn;
    tvBasicPAY_AMOUNT: TcxGridDBColumn;
    tvBasicCON_NO: TcxGridDBColumn;
    tvBasicCON_NAME: TcxGridDBColumn;
    tvBasicPAY_STATE: TcxGridDBColumn;
    tvBasicSOURCE_TYPE: TcxGridDBColumn;
    tvBasicEMP_NO: TcxGridDBColumn;
    tvBasicEMP_NAME: TcxGridDBColumn;
    lvEXP_COMP: TcxGridLevel;
    cxGroupBox1: TcxGroupBox;
    Label2: TLabel;
    Label4: TLabel;
    Label1: TLabel;
    Label3: TLabel;
    edtDateFrom: TcxDateEdit;
    edtDateTo: TcxDateEdit;
    cbPayState: TcxImageComboBox;
    cbSource: TcxImageComboBox;
    cxButton1: TcxButton;
    cxTabSheet2: TcxTabSheet;
    GrdEval: TcxGrid;
    tvEval: TcxGridDBTableView;
    tvEvalBILL_NO: TcxGridDBColumn;
    tvEvalCRT_DT: TcxGridDBColumn;
    tvEvalANONYMOUS_TAG: TcxGridDBColumn;
    tvEvalEVAL_SCORE: TcxGridDBColumn;
    tvEvalEVAL_TAG: TcxGridDBColumn;
    tvEvalEVAL_CONTENT: TcxGridDBColumn;
    tvEvalDEST_TYPE: TcxGridDBColumn;
    tvEvalCUST_NAME: TcxGridDBColumn;
    lvEval: TcxGridLevel;
    cxGroupBox2: TcxGroupBox;
    Label5: TLabel;
    Label6: TLabel;
    edtBegin: TcxDateEdit;
    edtEnd: TcxDateEdit;
    cxButton2: TcxButton;
    crsEval: TClientRowSet;
    crsEvalID: TStringField;
    crsEvalORDER_ID: TStringField;
    crsEvalEMP_NO: TStringField;
    crsEvalEMP_NAME: TStringField;
    crsEvalEVAL_SCORE: TFloatField;
    crsEvalEVAL_CONTENT: TStringField;
    crsEvalCRT_DT: TStringField;
    crsEvalCHANNEL_ID: TStringField;
    crsEvalUPD_DT: TStringField;
    crsEvalVERSION: TIntegerField;
    crsEvalDISABLED: TSmallintField;
    crsEvalSTATUS: TSmallintField;
    crsEvalEVAL_TAG: TStringField;
    crsEvalCUST_ID: TStringField;
    crsEvalANONYMOUS_TAG: TSmallintField;
    crsEvalDEST_TYPE: TSmallintField;
    crsEvalCUST_NAME: TStringField;
    crsEvalBILL_NO: TStringField;
    crsRecord: TClientRowSet;
    crsRecordID: TStringField;
    crsRecordORDER_ID: TStringField;
    crsRecordTRADE_NO: TStringField;
    crsRecordCRT_BY: TStringField;
    crsRecordSOURCE_TYPE: TSmallintField;
    crsRecordPAY_STATE: TSmallintField;
    crsRecordPAY_TIME: TStringField;
    crsRecordPAY_AMOUNT: TFloatField;
    crsRecordEMP_NO: TStringField;
    crsRecordEMP_NAME: TStringField;
    crsRecordCRT_DT: TStringField;
    crsRecordCHANNEL_ID: TStringField;
    crsRecordUPD_DT: TStringField;
    crsRecordVERSION: TIntegerField;
    crsRecordDISABLED: TSmallintField;
    crsRecordSTATUS: TSmallintField;
    crsRecordEVAL_ID: TStringField;
    crsRecordOUT_TRADE_NO: TStringField;
    crsRecordBILL_NO: TStringField;
    crsRecordCON_NO: TLargeintField;
    crsRecordCON_NAME: TStringField;
    dsRecord: TDataSource;
    dsEval: TDataSource;
    ActionList1: TActionList;
    actQuery: TAction;
    actFind: TAction;
    procedure actQueryExecute(Sender: TObject);
    procedure actFindExecute(Sender: TObject);
  private
    { Private declarations }
  public
    procedure InitForm;
    { Public declarations }
  end;

var
  FrmRewardRecord: TFrmRewardRecord;

implementation

{$R *.dfm}

uses ucommFunction, uDm, Console;

{ TFrmRewardRecord }

procedure TFrmRewardRecord.actFindExecute(Sender: TObject);
var
  sqls:string;
begin
  sqls:='select t.*,b.bill_no from TSP_ORDER_EVAL t left join tsp_order b on t.order_id=b.order_id '+
        ' where t.CRT_DT>='+QuotedStr(edtBegin.Text)+' and t.CRT_DT<='+QuotedStr(edtEnd.Text+' 23:59:59');
  OpenDataSet(sqls,crsEval);
end;

procedure TFrmRewardRecord.actQueryExecute(Sender: TObject);
var
  sqls:string;
begin
  sqls:='select a.*,b.bill_no,c.con_no,c.con_name from TSP_ORDER_REWARD a left join'+
        ' tsp_order b on a.order_id=b.order_id left join bas_member c on a.crt_by=c.id ' +
        ' where b.group_code='+QuotedStr(userInfo.groupCode)+' and a.pay_time>='+QuotedStr(edtDateFrom.Text)+' and a.pay_time<='+QuotedStr(edtDateTo.Text+' 23:59:59');
  if Trim(cbPayState.Text)<>'' then
    sqls:=sqls+' and pay_state='+VarToStr(cbPayState.EditValue);
  if Trim(cbSource.Text)<>'' then
    sqls:=sqls+' and SOURCE_TYPE='+VarToStr(cbSource.EditValue);
  OpenDataSet(sqls,crsRecord);
end;

procedure TFrmRewardRecord.InitForm;
begin
  edtDateFrom.Date:=Date-30;
  edtDateTo.Date:=Date;
  edtBegin.Date:=Date-30;
  edtEnd.Date:=Date;
end;

end.
